package com.zmn.plat.common.util;

import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.string.InitialUtil;
import com.zmn.common.utils.string.StringUtil;

import java.util.Arrays;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author tanbiao
 * @description
 * @modifier
 * @since 2021/1/13 16:22
 **/
public class SimpleSpellUtil {
    // 默认简称长度
    private static final int DEFAULT_LENGTH = 10;


    public static String parseNameToSimpleSpell(String name, Integer length) {
        if (StringUtil.isBlank(name)) {
            return "";
        }
        if (NumberUtil.isNullOrZero(length)) {
            length = DEFAULT_LENGTH;
        }

        String simpleSpell = InitialUtil.getInitial(name);
        if (StringUtil.isNotBlank(simpleSpell)) {
            if (simpleSpell.length() > length) {
               return simpleSpell.substring(0, length);
            } else {
                return simpleSpell;
            }
        }
        return "";

    }

    public static void main(String[] args) {
        String test = SimpleSpellUtil.parseNameToSimpleSpell("发哈市奖罚单11过卡航空公司的", 10);
        System.out.println(test);
    }
}
